package com.jykj.modbus.equipment.dao;

import com.jykj.modbus.equipment.dao.guard.EquipmentDaoGuard;
import com.jykj.modbus.equipment.entity.guard.Equipment;
import com.jykj.modbus.equipment.entity.guard.EquipmentData;
import com.jykj.modbus.equipment.entity.guard.EquipmentMessage;
import com.jykj.util.StringUtils;
import org.springframework.stereotype.Repository;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Repository
public class EquipmentDao extends EquipmentDaoGuard {

    /**查询设备方法**/
    public List<Equipment> selectEquipmentList(Equipment obj) {
        String hql = " from Equipment where 1=1";
        Map<String, Object> param = new HashMap<>();
        //设备识别码
        if (obj.getIdentificationCode() != null) {
            hql += " and identificationCode = :identificationCode";
            param.put("identificationCode",  obj.getIdentificationCode() );
        }
        //传感器类型
        if (obj.getSensorType() != null) {
            hql += " and sensorType = :sensorType";
            param.put("sensorType",  obj.getSensorType() );
        }
        //波特率
        if (obj.getBaudRate() != null) {
            hql += " and baudRate = :baudRate";
            param.put("baudRate",  obj.getBaudRate() );
        }
        //串口号
        if (obj.getSerialPort() != null) {
            hql += " and serialPort = :serialPort";
            param.put("serialPort",  obj.getSerialPort() );
        }
        return baseDao.findByHql(hql, param);
    }

    /**通过条件查询设备方法**/
    public List<EquipmentMessage> selectEquipmentMessage(EquipmentMessage obj) {
        String hql = " from EquipmentMessage where 1=1";
        Map<String, Object> param = new HashMap<>();
        //设备识别码
        if (obj.getSensorType() != null) {
            hql += " and sensorType = :sensorType";
            param.put("sensorType",  obj.getSensorType() );
        }
        //设备指令报文类型
        if (obj.getMessageType() != null) {
            hql += " and messageType = :messageType";
            param.put("messageType",  obj.getMessageType() );
        }
        List<EquipmentMessage> list = baseDao.findByHql(hql, param);
        return list;
    }

}
